package core.java.sortcode;

import java.util.Arrays;

public class ComparableDemo{
    public static void main(String[] args) {
        Person ps[] = {new Person(2),new Person(1),new Person(3)};
        Arrays.sort(ps);
        for(Person p : ps){
            System.out.println(p.getAge());
        }
    }
}
class Person implements Comparable<Person> {
	private int age;

	public Person(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public int compareTo(Person p) {
		return this.age - p.getAge();
	}
}